module.exports = {
	// 如: api 基础路径地址, 在项目中使用组合的方式组合出 api 路径，便于后期 api 的接口更换及维护
	imgServer: "",
	/**
	 * 格式化money,(123456=>123,456.00)
	 * num:string or number
	 */
	changeTwoDecimal: function(vals) {
		let val = vals / 100
		if (val) {
			val = val.toString().replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
			let val1 = parseFloat(val).toFixed(2); //保留两位小数
			let val2 = val1.toString();
			let arr = val2.split('.');
			let arr1 = arr[0].split('');
			let str3 = "";
			let arr2 = [];
			for (let i = arr1.length - 1, j = 0; i >= 0; i--, j++) {
				str3 = '' + arr1[i] + str3;
				if (j % 3 == 2) {
					arr2.unshift(str3)
					str3 = "";
				} else if (i == 0) {
					arr2.unshift(str3)
				}
			}
			let str4 = arr2.join(',');
			let str5 = str4 + '.' + arr[1];
			return str5;
		} else {
			return 0;
		}
	},
	//最近的时间
	getRecentTime(day, type = 0) {
		var today = new Date();
		var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
		today.setTime(targetday_milliseconds); //注意，这行是关键代码		
		var tYear = today.getFullYear();
		var tMonth = today.getMonth();
		var tDate = today.getDate();
		var Dhour = today.getHours();
		var Dminute = today.getMinutes() < 10 ? '0' + today.getMinutes() : today.getMinutes();
		var Dsecond = today.getSeconds() < 10 ? '0' + today.getSeconds() : today.getSeconds();
		tMonth = doHandleMonth(tMonth + 1);
		tDate = doHandleMonth(tDate);
		if (type == 0) {
			return tYear + "-" + tMonth + "-" + tDate + " " + Dhour + ":" + Dminute + ":" + Dsecond;
		} else if (type == 1) {
			return tYear + "-" + tMonth + "-" + tDate + " " + "00:00:00";
		} else if (type == 2) {
			return tYear + "-" + tMonth + "-" + tDate + " " + "23:59:59";
		} else if (type == 3) {
			return tYear + "-" + tMonth + "-" + tDate + " " + Dhour + ":" + Dminute;
		}

		function doHandleMonth(month) {
			var m = month;
			if (month.toString().length == 1) {
				m = "0" + month;
			}
			return m;
		}
	},
	//获取菜单参数
	getUrlParam: function(name) {
		const pages = getCurrentPages()
		const currentPage = pages[pages.length - 1]
		const url = currentPage.route
		const options = currentPage.options
		let urlWithArgs = `/${url}?`
		for (let key in options) {
			const value = options[key]
			urlWithArgs += `${key}=${value}&`
		}
		urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1);
		const search = "?" + urlWithArgs.split('?')[1];
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
		var r = search.substr(1).match(reg); //匹配目标参数
		if (r != null) return unescape(r[2]);
		return null; //返回参数值
	}


}
